package cn.sdormitory.controller;

import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.common.dto.ResultMsg;
import cn.sdormitory.dormitoryHygiene.req.SubmitHygieneInfoReq;
import cn.sdormitory.dormitoryHygiene.vo.AppDorHygieneCountVO;
import cn.sdormitory.dormitoryHygiene.vo.AppDormitoryHygieneVO;
import cn.sdormitory.dormitoryHygiene.vo.DormitoryHygieneListVO;
import cn.sdormitory.service.AppDormitoryHygieneService;
import cn.sdormitory.tencent.service.TencentCosFileService;
import io.jsonwebtoken.lang.Assert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : yy
 * @date: 2024/9/14 10:48
 * @description:
 */
@RestController
@RequestMapping("/app/dormitory/hygiene")
@Api("APP端卫生管理接口")
public class AppDormitoryHygieneController {
    @Resource
    private AppDormitoryHygieneService appDormitoryHygieneService;

    @Autowired
    private TencentCosFileService cosFileService;

    @ApiOperation(value = "根据楼栋，楼层,检查时间段查询当层宿舍今日卫生检查情况")
    @GetMapping("/getEachLayerDormitoryHygiene")
    public ResultMsg getEachLayerDormitoryHygiene(String buildNo, String floorNo, Integer checkItemSpan) {
        List<AppDormitoryHygieneVO> appDormitoryHygieneVOList =appDormitoryHygieneService.getEachLayerDormitoryHygiene(buildNo,floorNo,checkItemSpan);
        return  ResultMsg.BY_SUCCESS("获取成功", appDormitoryHygieneVOList);
    }

    @ApiOperation(value = "查询宿舍卫生检查情况")
    @GetMapping("/getDormitoryHygieneDetails")
    public ResultMsg getDormitoryHygieneDetails(Long dormitoryId,Integer checkItemSpan,String rq){
        AppDormitoryHygieneVO appDormitoryHygieneVO =appDormitoryHygieneService.getDormitoryHygieneDetails(dormitoryId,checkItemSpan,rq);
        return ResultMsg.BY_SUCCESS("获取成功", appDormitoryHygieneVO);
    }

    @ApiOperation(value = "当日卫生检查提交")
    @PostMapping("/submitHygiene")
    public CommonResult submitHygiene(@RequestBody SubmitHygieneInfoReq hygieneInfoReq) {
        appDormitoryHygieneService.submitHygiene(hygieneInfoReq);
        return CommonResult.success();
    }

    @ApiOperation(value = "宿舍卫生检查结果消息推送")
    @GetMapping("/pushDorHygieneInfo")
    public CommonResult pushDorHygieneInfo(Long dormitoryId,Integer grade,Integer checkTimeSpan,String rq) {
        appDormitoryHygieneService.pushDorHygieneInfo(dormitoryId,grade,checkTimeSpan,rq);
        return CommonResult.success();
    }





    @ApiOperation(value = "根据用户id查询宿舍卫生统计信息-仅限班主任和部门经理使用")
    @GetMapping("/getAppDorHygieneCount")
    public CommonResult<List<AppDorHygieneCountVO>> getAppDorHygieneCount(@RequestParam("userId") Long userId,
                                                                          @RequestParam("rq") String rq) {
        return CommonResult.success(appDormitoryHygieneService.getAppDorHygieneCount(userId,rq));
    }


    @ApiOperation(value = "根据班级id查询不合格的宿舍卫生信息")
    @GetMapping("/getBadDorHygieneByClassId")
    public CommonResult<List<DormitoryHygieneListVO>> getBadDorHygieneByClassId(@RequestParam("classId") Long classId,
                                                                             @RequestParam("rq") String rq){
        List<DormitoryHygieneListVO> dormitoryHygieneListVOS = appDormitoryHygieneService.getBadDorHygieneByClassId(classId,rq);
        return CommonResult.success(dormitoryHygieneListVOS);
    }

    @ApiOperation(value = "上传宿舍卫生图片到腾讯云oos")
    @PostMapping("/uploadHygienePhoto")
    public CommonResult<String> uploadHygienePhoto(@RequestParam(value = "file") MultipartFile file) {
        String photo = cosFileService.uploadImg(file);
        Assert.notNull(photo,"上传人脸照片到腾讯云失败");
        return CommonResult.success(photo);
    }
}
